package cn.zhangyong.dbframelearn.bean;

import com.j256.ormlite.dao.ForeignCollection;
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.field.ForeignCollectionField;
import com.j256.ormlite.table.DatabaseTable;

import java.io.Serializable;

/**
 * description:
 * autour: zhangyong
 * date: 2019/4/3 9:56
 * update: 2019/4/3
 * version:
 */
@DatabaseTable(tableName = "author")
public class Author implements Serializable {
    @DatabaseField(generatedId = true)
    private int id;
    @DatabaseField(columnName = "author_name", dataType = DataType.STRING, canBeNull = false)
    private String name;
    @DatabaseField(columnName = "author_password", dataType = DataType.STRING)
    private String psw;

    @ForeignCollectionField(eager = true)
    private ForeignCollection<Note> notes;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPsw() {
        return psw;
    }

    public void setPsw(String psw) {
        this.psw = psw;
    }

    public ForeignCollection<Note> getNotes() {
        return notes;
    }

    public void setNotes(ForeignCollection<Note> notes) {
        this.notes = notes;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"id\":")
                .append(id);
        sb.append(",\"name\":\"")
                .append(name).append('\"');
        sb.append(",\"psw\":\"")
                .append(psw).append('\"');
        sb.append(",\"notes\":")
                .append(notes);
        sb.append('}');
        return sb.toString();
    }
}
